package com.abe.libquick.utils;

import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.provider.Settings;

import androidx.annotation.NonNull;

public class LocHelper {
    // 返回1为仅支持GPS ；2为仅支持网络定位；3为均支持
    public static int isCanLocation(@NonNull Context context) {
        int i = 0;
        LocationManager locationManager;
        locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        if (!locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER)
                & !locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            // 无法定位：1、提示用户打开定位服务；2、跳转到设置界面
            DialogHelper.normalCC(context, "提示", "位置服务未开启，是否前往开启！",
                    (dialog, which) -> {
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        context.startActivity(intent);
                        dialog.dismiss();
                    }, (dialog, which) -> dialog.dismiss());
            return 0;
        } else {
            if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                i = i + 1;
            }
            if (locationManager
                    .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                i = i + 2;
            }
            return i;
        }
    }
}
